package com.zycfc.zsf.boot.util.io;

import com.google.common.io.*;
import java.net.*;
import java.io.*;
import java.nio.charset.*;
import java.util.*;

public abstract class ResourceUtils
{
    public static File asFile(final String resourceName) throws IOException {
        try {
            return new File(Resources.getResource(resourceName).toURI());
        }
        catch (URISyntaxException e) {
            return null;
        }
    }
    
    public static File asFile(final Class<?> contextClass, final String resourceName) throws IOException {
        try {
            return new File(Resources.getResource((Class)contextClass, resourceName).toURI());
        }
        catch (URISyntaxException e) {
            return null;
        }
    }
    
    public static InputStream asStream(final String resourceName) throws IOException {
        return Resources.getResource(resourceName).openStream();
    }
    
    public static InputStream asStream(final Class<?> contextClass, final String resourceName) throws IOException {
        return Resources.getResource((Class)contextClass, resourceName).openStream();
    }
    
    public static String toString(final String resourceName) throws IOException {
        return Resources.toString(Resources.getResource(resourceName), StandardCharsets.UTF_8);
    }
    
    public static String toString(final Class<?> contextClass, final String resourceName) throws IOException {
        return Resources.toString(Resources.getResource((Class)contextClass, resourceName), StandardCharsets.UTF_8);
    }
    
    public static List<String> toLines(final String resourceName) throws IOException {
        return (List<String>)Resources.readLines(Resources.getResource(resourceName), StandardCharsets.UTF_8);
    }
    
    public static List<String> toLines(final Class<?> contextClass, final String resourceName) throws IOException {
        return (List<String>)Resources.readLines(Resources.getResource((Class)contextClass, resourceName), StandardCharsets.UTF_8);
    }
}
